package cn.edu.flink.tutorial.wordcount;

import cn.edu.flink.tutorial.wordcount.flatmap.WordCountFlatMap;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.AggregateOperator;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;

public class WordCountDataSet {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        DataSource<String> text = env.readTextFile("src/main/resources/word.txt");
        AggregateOperator<Tuple2<String, Integer>> sum =
                text.flatMap(new WordCountFlatMap())
                .groupBy(0)
                .sum(1);

        //打印输出
        sum.print();
    }
}
